/**
 * @class   wosh::communication::NotificationConversion
 * @brief   This class holds a wosh::Notification object and conversion
 *          (as translation) parameters.
 *   
 * @see     wosh::services::CommunicationManagerBundle
 ****************************************************************************
 * @version $Id: NotificationConversion.h 2863 2010-08-07 04:28:58Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Communication_NotificationConversion_H__
 #define __WOSH_Communication_NotificationConversion_H__

 #include <woshDefs.h>
 #include <core/Serialization.h>
 #include <core/Notification.h>



namespace wosh {
 namespace communication {


class NotificationConversion : public virtual ISerializable
 {
	WOSH_SERIALIZABLE(wosh::communication::NotificationConversion)
	WOSH_COMPARE_RTTI(wosh::communication::NotificationConversion)

	public:

		NotificationConversion( Notification* original_notification = NULL )
		 {
			this->original = NULL;

			this->outType = Notification::TYPE_UNKNOWN;
			this->outProtocol = Notification::PROTOCOL_UNKNOWN;
			this->outLanguage = "";
			
			setOriginal(original_notification);
		 }

		NotificationConversion( const NotificationConversion& m )
		 {
			this->original = NULL;

			*this = m;
		 }

		virtual ~NotificationConversion()
		 {
			if ( this->original != NULL )
				delete this->original; this->original = NULL;
		 }


//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:

		void setOriginal( Notification* original_notification )
		 {
			if ( this->original != NULL )
				delete this->original; this->original = NULL;
			this->original = original_notification;
		 }

		void setLanguage( const std::string& value ) 		{ this->outLanguage = value; }

		void setProtocol( Notification::PROTOCOL proto )	{ this->outProtocol = proto; }

		void setNotificationType( Notification::TYPE type )	{ this->outType = type; }

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:

		inline bool hasOriginal() const					{ return (this->original != NULL); }

		inline const Notification* getOriginal() const	{ return this->original; }
		inline Notification* getOriginal()				{ return this->original; }


		const std::string& getLanguage() const			{ return this->outLanguage; }
		std::string& getLanguage()						{ return this->outLanguage; }

		Notification::PROTOCOL getProtocol() const		{ return this->outProtocol; }

		Notification::TYPE getNotificationType() const	{ return this->outType; }

//@}
/** @name Operators Overloading
 * @{
 ******************************************************************************/
	public:
		virtual NotificationConversion& operator=(const NotificationConversion& m)
		 {
			if (this == &m) return *this; // same object?

			this->outType = m.outType;
			this->outProtocol = m.outProtocol;
			this->outLanguage = m.outLanguage;

			if ( this->original != NULL )
				delete this->original;
			this->original = NULL;

			if ( m.original != NULL )
				this->original = m.original->clone();

			return *this;
		 }

		virtual bool operator==(const NotificationConversion &other) const
		 {
			if ( this->outType != other.outType )
				return false;

			if ( this->outProtocol != other.outProtocol )
				return false;

			if ( this->outLanguage != other.outLanguage )
				return false;

			return true;
		 }

		virtual bool operator!=(const NotificationConversion &other) const { return !(*this == other);  }

//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual std::string toString() const				{ return ""; }
		virtual bool updateHash( DataHashContext* hash_context ) const {
			if ( hash_context == NULL ) return false;
			bool ret = true;
			if ( this->original != NULL )
				ret = this->original->updateHash(hash_context) & ret;
			ret = hash_context->update( this->outType ) & ret;
			ret = hash_context->update( this->outProtocol ) & ret;
			ret = hash_context->update( this->outLanguage ) & ret;
			return ret;
		 }
//@}

/** @name Internal vars
 * @{
 ******************************************************************************/
	protected:
		wosh::Notification* original;			///<

		Notification::TYPE outType;				///<
		Notification::PROTOCOL outProtocol;		///<
		std::string outLanguage;				///<

//@}

}; // class def

 }; // namespace communication
}; // namespace wosh

#endif //__WOSH_Communication_NotificationConversion_H__
